import type { Lyric } from "@/models/songinfo.ts"
// 定义歌词数据类型

//解析歌词数据
export const parseLyrics = (dataStr: string): Lyric[] => {
  const lines = dataStr.split('\n')
  const lyrics: Lyric[] = []
  for (const line of lines) {
    const matchRegex = /\[(\d{2}):(\d{2})\.(\d{2,3})\](.+)/;
    const match = line.match(matchRegex)
    if (match) {
      const [, minutes, seconds, milliseconds, content] = match;
      const timestamp = parseInt(minutes) * 60 + parseInt(seconds) + parseInt(milliseconds) / 1000;
      lyrics.push({ timestamp, content });
    }
  }

  return lyrics
}
